package InvestmentPojo;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



public class ContactUsSubmitAction extends Action {


	  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
		 
		 
		  Properties props = new Properties(System.getProperties());
		  FileInputStream fis=new FileInputStream("D:/venki/Investment_In_India2/WebContent/WEB-INF/classes/ImmovableInIndia.properties");
		  props.load(fis);

		  
		  String samplpleVar = request.getParameter("a").toString();
		  String answer = props.getProperty(samplpleVar);
		  System.out.println("33333333333333333333"+samplpleVar);
		  //logic for getting the answer:
		  
		  HashMap map = new HashMap(props);
		  LinkedHashMap linkedMap = new LinkedHashMap();
		  
		  Iterator propIterator = map.entrySet().iterator();
		  
		  while(propIterator.hasNext()){
			  
			  Map.Entry pairs = (Map.Entry)propIterator.next();
			  
			  String key = pairs.getKey().toString();
			  String arr[] = key.toString().split("~");
			  
			  if(samplpleVar.equals(arr[0])){
				  
				  	if("ans1".equals(arr[1])){
				  		linkedMap.put("Eligiblity", props.getProperty(key));
				  	}
				  	
				  	else if("ans2".equals(arr[1])){
				  		linkedMap.put("purchase consideration", props.getProperty(key));
				  	}
				  	
				  	else if("ans3".equals(arr[1])){
				  		linkedMap.put("repatriation of Sale Proceeds", props.getProperty(key));
				  	}
				  	
				  	else if("ans4".equals(arr[1])){
				  		linkedMap.put("Reporting", props.getProperty(key));
				  	}
				  	
					else if("ans5".equals(arr[1])){
				  		linkedMap.put("Note", props.getProperty(key));
				  	}
				  
			  }
		  }
		  
		  //System.out.println(linkedMap);
		  
		  request.setAttribute("ANSWER", linkedMap);
		  return mapping.findForward("succ"); // Not forwarding to anywhere, response is fully-cooked
	    
	  
	  }

}
